<template>
  <div class="root">
    <m-header title="提现">
      <div slot="left" v-on:click="$router.go(-1)"><img class="m-icon-img margin-right-10" src="../../assets/images/menu_back.png" /></div>
      <div slot="right"><img class="m-icon-img margin-right-10" src="../../assets/images/menu_more.png" /></div>
    </m-header>

    <div class="content">
      <div class="amount-con">
        <div class="amount-title">
          提现金额
        </div>
        <div class="amout-data">
          <span class="money-icon">￥</span>
          <mu-text-field hintText="最多提现200元" v-model.number="amount" type="number" />
        </div>

        <div class="amount-title">
          支付宝账号
        </div>
        <div class="amout-data">
          <mu-text-field hintText="请输入你的支付宝账号" v-model="alipayAccount" />
        </div>

        <div class="withdraw-description">
          提现说明:
          <br/> 1. 1基金可提现0.8元
          <br/> 2. 最低提现金额为50元
          <br/> 3. 提现审核后将于1个工作日内将提现金额打入到您的支付宝账号
          <br/>
        </div>

      </div>

      <div class="buttonCon">
        <mu-raised-button label="提现到支付宝" class="raised-button" backgroundColor="#fd4ba3" @click="withdraw(1)" />
        <mu-raised-button label="提现到余额" class="raised-button" backgroundColor="#fd4ba3" @click="withdraw(0)" />
        <!--<mu-raised-button label="提现到支付宝" class="raised-button" backgroundColor="#02a588" @click="withdraw(1)" />
        <mu-raised-button label="提现到余额" class="raised-button" backgroundColor="#02a588" @click="withdraw(0)" />-->
      </div>
    </div>
  </div>
</template>

<script>
  import mHeader from '../../components/header'
  import util from '../../util/util.js'
  import {
    mapActions
  } from 'vuex'
  import {
    SET_MY_WALLET

  } from '../../store/myWallet.js'
  export default {
    components: {
      mHeader
    },
    data() {
      var amount;
      return {
        alipayAccount: '',
        amount
      }
    },
    methods: {
      ...mapActions([SET_MY_WALLET]),

      withdraw(type) {
        // type 0：提现到余额  1：提现到支付宝

        if (this.amount <= 0) return util.toast('请输入正确的金额');
        if (type === 1 && this.alipayAccount.length === 0) return util.toast('请输入正确的支付宝账号');

        var _this = this;
        this.$http.post('user/withdraw/friendfund', {
          thirdAccount: _this.alipayAccount,
          amount: _this.amount,
          destination: type
        }).then(
          function (response) {
            if (response.data.code === '0') {
              if (response.data.data.moneyBag != null) {
                _this.SET_MY_WALLET(response.data.data.moneyBag);
              }
              util.toast(response.data.msg);
              _this.$router.go(-1);
            }
          }
        );
      }
    }
  }

</script>

<style lang="less" scoped>
  /*@import "../../assets/less/common.less";*/
  .withdraw-description {
    color: #888888;
  }

</style>
